local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent(),script.Parent.Name.."_"..script.Name);

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
     self.player=self.parent

     self.player.BattleSateEvent:Connect(function(isBattle,battle)
        self.Battle=battle
        if isBattle then
            self:EnterBattle()
        else
            self:OutBattle()
        end

    end)

    -- 寻找参战者监听
    self.player.FindCombatantEvent:Connect(function(guid)
         return self:findMonsterByGuid(guid)
    end)

end;

function M.dtor(self)
	M.super.dtor(self);
end


--进入一场战斗（子类复写）
function M.EnterBattle(self)


end

--离开一场战斗（子类复写）
function M.OutBattle(self)


end

 --获取攻击力
 function M.GetAttackDamge(self,weapon)
    local baseList= self.player.AttackValueBaseEvent:Action(weapon)
   local mulList= self.player.AttackValueMulEvent:Action(weapon)
   local mul2List= self.player.AttackValueMul2Event:Action(weapon)

   local addList= self.player.AttackValueAddEvent:Action(weapon)

   local base=0
   for _,v in pairs(baseList) do
        base=base+v
   end

   local mul=1

   for _,v in pairs(mulList) do
        mul=mul+v
   end

   local mul2=1
   for _,v in pairs(mul2List) do
        mul2=mul2*v
   end


   local add=0

   for _,v in pairs(addList) do
         add=add+v
    end

    return base*mul*mul2+add
end



 --获取攻击Cd
 function M.GetAttackCd(self,weapon)
    local baseList= self.player.AttackCdBaseEvent:Action(weapon)
   local mulList= self.player.AttackCdMulEvent:Action(weapon)
   local addList= self.player.AttackCdAddEvent:Action(weapon)

   local base=0
   for _,v in pairs(baseList) do
        base=base+v
   end

   local mul=1

   for _,v in pairs(mulList) do
        mul=mul+v
   end

   local add=0

   for _,v in pairs(addList) do
         add=add+v
    end

    return base*(1/mul)+add
end


--开启攻击CD检测
function M.OpenAttackCdCheck(self)

    if self.GetAttackCDEventCon then
        return 
   end

    --检测攻击CD
    self.GetAttackCDEventCon=  self.player.GetAttackCDEvent:Connect(function(weapon,tp)
        return self:GetAttackCd(weapon)
    end)

end

--关闭攻击CD检测
function M.CloseAttackCdCheck(self)
    if self.GetAttackCDEventCon then
        self.GetAttackCDEventCon:Disconnect()
        self.GetAttackCDEventCon=nil
    end
end

--开启攻击伤害检测
function M.OpenAttackDamgeCheck(self)

    if self.GetAttackDamgeEventCon then
        return 
   end

    --检测攻击CD
    self.GetAttackDamgeEventCon=  self.player.GetAttackDamgeEvent:Connect(function(weapon,tp)
        return self:GetAttackDamge(weapon)
    end)

end

--关闭攻击伤害检测
function M.CloseAttackDamgeCheck(self)
    if self.GetAttackDamgeEventCon then
        self.GetAttackDamgeEventCon:Disconnect()
        self.GetAttackDamgeEventCon=nil
    end
end


--开启攻击对象寻找监听
function M.OpenFindAttackTargetCheck(self)

    -- print("寻找攻击目标监听--Open->")
    if self.FindAttackTargetEventCon then
        return 
   end

    --寻找目标
    self.FindAttackTargetEventCon=self.player.FindAttackTargetEvent:Connect(function(character,...)
        -- print("---正在寻找--->",self.Battle.FindNearMonster)
        if self.Battle then
           local obj= self.Battle:FindNearMonster(character,...)
            return obj
        end
    end)
    

end

--关闭攻击对象寻找监听
function M.CloseFindAttackTargetCheck(self)
    -- print("寻找攻击目标监听--.Close--->")
    if self.FindAttackTargetEventCon then
        self.FindAttackTargetEventCon:Disconnect()
        self.FindAttackTargetEventCon=nil
    end
end

--通过guid寻找怪物
function M.findMonsterByGuid(self,guid)

    if self.Battle then
        return self.Battle:findMonsterByGuid(guid)
    end
end

--是否在战斗中
function M.GetIsBattle(self)
    return self.Battle
end


return M